package com.example.filepersistence;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class FilePersistenceActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button btnSalvar = (Button) findViewById(R.id.btnSalvar);
        
        btnSalvar.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				EditText txtNome = (EditText) findViewById(R.id.txtNome);
				EditText txtEmail = (EditText) findViewById(R.id.txtEmail);
				EditText txtFile = (EditText) findViewById(R.id.txtFile);
		
				String nome = txtNome.getText().toString();
				String email = txtEmail.getText().toString();
				String filename = txtFile.getText().toString();

				try {
					FileOutputStream fis = openFileOutput(filename, MODE_PRIVATE);
					OutputStreamWriter isr = new OutputStreamWriter(fis);
					
					isr.write("Nome: " + nome + "\n");
					isr.write("email: " + email + "\n");
					isr.close();

				} catch (FileNotFoundException e) {
				} catch (IOException e) {
				}
			}
		});
    }
}